<?php

global $_CONF;

$_CONF['debug'] = false;

App::loadAjax('Account', array
(
	'getUsersOnline',
	'changeImStatus',
	'searchFriends',
	'checkMessages',
	'updateUsersOnline',
	'deleteRequest',
	'acceptRequest',
	'saveUserSetting'
));

if ( !isset($_POST['xajax']) )
{
	App::membersOnly();
	
	$oDb =& Database::get();
	$oTpl =& App::getTemplate();

	$iCnt = $oDb->getField("SELECT COUNT(*) FROM ". App::getT('msg_online') ." WHERE userid = '". App::getUser('id') ."'");
	if ( !$iCnt )
	{
		$oDb->insert(App::getT('msg_online'), array('userid' => App::getUser('id'), 'time' => time()));
	}

	$aOptions = App::getOptions('im_status');
	$aStatus = array();
	$sCurrent = (isset($aOptions[App::getUser('im_status')]) ? $aOptions[App::getUser('im_status')] : '');
	foreach( $aOptions as $iKey => $sValue )
	{
		$aStatus[] = array('key' => $iKey, 'name' => $sValue);
	}

	$sJavaScript = '<script type="text/javascript">
		function confirmExit()
		{
			opener.window.document.getElementById(\'ajax_temp_content\').innerHTML=\'<iframe frameborder="0" width="0" height="0" src="' . App::getParam('url') . 'design/static/ajax.php?intelajax[module]=Account&intelajax[function]=deleteSessions"><\/iframe>\';
			closeChildWindows();
		}
		window.onunload = confirmExit;
		function playsound(fn)
		{
			var d = document.getElementById(fn);
			d.innerHTML = \'<embed src="'. App::getParam('url') .'file/player/beep.wav" autostart="true" hidden="true" volumn="100" look="false" />\';
		}
	</script>';

	$oTpl->assign(array
	(
		'sUser' => App::getUser('user'),
		'bImSetting' => App::getUser('msg_event'),
		'aOptions' => $aStatus,
		'sCurrent' => $sCurrent,
		'sExtraHeader' => "". $sJavaScript ."<script type=\"text/javascript\">\n\t\twindow.onload=clicktoHideAll;\n\t\tvar sDisplayIds = new Array('search_box', 'user_status', 'user_setting');\n\t window.resizeTo('340', '680');</script>"
	));

	$oTpl->setTemplateFile('index.html');
}
?>